# _*_ coding:utf-8 _*_
# @Time  : 2023.11.03
# @Author: zizlee
from fastapi import APIRouter
from response import APIResponse
from db_utils import BaseDatabaseConnection
from settings import STATIC_HOST

common_router = APIRouter()


class Banner:
    def banners(self):
        with BaseDatabaseConnection() as conn:
            conn.cursor.execute("SELECT id,img_src,router_name,router_path FROM ruizhi_banner WHERE is_active=1 ORDER BY sort_num;")
            banners = list(conn.cursor.fetchall())
        for b in banners:
            b['img_src'] = STATIC_HOST + b['img_src']
        return APIResponse.success(data=banners)


@common_router.get('/banners/')
def common_banners():
    return Banner().banners()
